package com.yk.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.system.domain.SysIndexPicture;
import com.yk.system.service.ISysIndexPictureService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;
import org.springframework.stereotype.Controller;

/**
 * 首页图片Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/system/indexPicture")
public class SysIndexPictureController extends BaseController
{
    private String prefix = "system/indexPicture";

    @Autowired
    private ISysIndexPictureService sysIndexPictureService;

    @RequiresPermissions("system:indexPicture:view")
    @GetMapping()
    public String indexPicture()
    {
        return prefix + "/indexPicture";
    }

    /**
     * 查询首页图片列表
     */
    @RequiresPermissions("system:indexPicture:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysIndexPicture sysIndexPicture)
    {
        startPage();
        List<SysIndexPicture> list = sysIndexPictureService.selectSysIndexPictureList(sysIndexPicture);
        return getDataTable(list);
    }

    /**
     * 导出首页图片列表
     */
    @RequiresPermissions("system:indexPicture:export")
    @Log(title = "首页图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysIndexPicture sysIndexPicture)
    {
        List<SysIndexPicture> list = sysIndexPictureService.selectSysIndexPictureList(sysIndexPicture);
        ExcelUtil<SysIndexPicture> util = new ExcelUtil<SysIndexPicture>(SysIndexPicture.class);
        return util.exportExcel(list, "首页图片数据");
    }

    /**
     * 新增首页图片
     */
    @RequiresPermissions("system:indexPicture:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页图片
     */
    @RequiresPermissions("system:indexPicture:add")
    @Log(title = "首页图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysIndexPicture sysIndexPicture)
    {
        return toAjax(sysIndexPictureService.insertSysIndexPicture(sysIndexPicture));
    }

    /**
     * 修改首页图片
     */
    @RequiresPermissions("system:indexPicture:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysIndexPicture sysIndexPicture = sysIndexPictureService.selectSysIndexPictureById(id);
        mmap.put("sysIndexPicture", sysIndexPicture);
        return prefix + "/edit";
    }



    /**
     * 修改保存首页图片
     */
    @RequiresPermissions("system:indexPicture:edit")
    @Log(title = "首页图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysIndexPicture sysIndexPicture)
    {
        return toAjax(sysIndexPictureService.updateSysIndexPicture(sysIndexPicture));
    }

    /**
     * 修改首页图片启用状态
     */
    @RequiresPermissions("system:indexPicture:changeStatus")
    @Log(title = "修改首页图片启用状态", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(SysIndexPicture sysIndexPicture)
    {
        return toAjax(sysIndexPictureService.changeStatus(sysIndexPicture));
    }

    /**
     * 删除首页图片
     */
    @RequiresPermissions("system:indexPicture:remove")
    @Log(title = "首页图片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysIndexPictureService.deleteSysIndexPictureByIds(ids));
    }
}
